﻿@{
    Layout = null;
}

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>用户登录</title>
    <link href="~/Content/bootstrap.min.css" rel="stylesheet" />
    <link href="~/Content/signin.css" rel="stylesheet" />
    <script src="~/Scripts/jquery-3.1.0.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script src="~/Asset/param.js"></script>
</head>

<body>
    <div class="container">
        <h2 class="form-signin-heading">登录入口</h2>
        <ul class="nav nav-tabs" role="tablist">
            <li role="presentation" class="active"><a href="#name_tab" role="tab" data-toggle="tab">会员登录</a></li>
            <li role="presentation"><a href="#phone_tab" role="tab" data-toggle="tab">手机验证码登录</a></li>
        </ul>
        <div class="tab-content">
            <div role="tabpanel" class="tab-pane active" id="name_tab">
                <label for="name" class="sr-only">密码</label>
                <input id="name" class="form-control" placeholder="输入用户名" name="name" required autofocus>
                <label for="pwd" class="sr-only">密码</label>
                <input type="password" id="pwd" class="form-control" name="pwd" placeholder="输入密码" required>
                <button id="nameLogin" class="btn btn-lg btn-primary btn-block" type="button" style="margin-top:5px;">登 录</button>
            </div>
            <div role="tabpanel" class="tab-pane" id="phone_tab">
                <label for="phone" class="sr-only">手机号</label>
                <input id="phone" class="form-control" placeholder="输入手机号" value="139999999" required autofocus>
                <label for="code" class="sr-only">验证码</label>
                <input id="code" class="form-control" placeholder="输入验证码" required>
                <div style="margin-top:5px;text-align:right;">
                    <button id="getCode" type="button" class="btn btn-default">获取短信验证码</button>
                </div>
                
                
                <button id="phoneLogin" class="btn btn-lg btn-primary btn-block" type="button" style="margin-top:5px;">登 录</button>
            </div>
        </div>
        <div id="msgNo" class="alert alert-danger" role="alert"></div>
            
    </div>
    <script type="text/javascript">
    $(function () {
        var msgNo = $("#msgNo");
        msgNo.hide();
        $("#getCode").click(function () {
            msgNo.hide();

            var phone = $("#phone").val();
            if (phone != null && phone.length > 0) {
                $.ajax({
                    url: '@Url.Action("GetSecurityCode", "Mobile")',
                    type: 'post',
                    data: { phone: phone },
                    success: function (data) {
                        if (data.Code == 1) {
                            $("#code").val(data.Data);
                        }
                    }
                });
            }
            else {
                msgNo.html("请输入手机号码！");
                msgNo.show();
            }
        });

        $("#nameLogin").click(function () {
            msgNo.hide();
            var name = $("#name").val();
            var pwd = $("#pwd").val();
            var ReturnUrl = $.request.queryString["ReturnUrl"];

            $.ajax({
                url: '@Url.Action("NameLogin", "Mobile")',
                type: 'post',
                data: { name: name, pwd: pwd, ReturnUrl: ReturnUrl },
                success: function (data) {
                    if (data.Code == 1) {
                        //if (data.Data)
                        //    {
                        //        window.location.href = data.Data;
                        //    }
                        //    else
                        //    {
                                window.location.href = '@Url.Action("Index", "Mobile")';
                            //}
                    }
                    else {
                        msgNo.html(data.Msg);
                        msgNo.show();
                    }
                }
            });

        });
        $("#phoneLogin").click(function () {
            msgNo.hide();
            var phone = $("#phone").val();
            var code = $("#code").val();
            var ReturnUrl = $.request.queryString["ReturnUrl"];
            $.ajax({
                url: '@Url.Action("PhoneLogin", "Mobile")',
                type: 'post',
                data: { phone: phone, code: code, ReturnUrl: ReturnUrl },
                success: function (data) {
                    if (data.Code == 1) {
                        //if (data.Data) {
                        //    window.location.href = data.Data;
                        //}
                        //else {
                            window.location.href = '@Url.Action("Index", "Mobile")';
                        //}
                    }
                    else {
                        msgNo.html(data.Msg);
                        msgNo.show();
                    }
                }
            });
        });
    });
    </script>
</body>
</html>

